part of "../dio.dart";

extension ResponseExtenstion on Response {
  // 返回码是2开头的话，就算是成功
  // 但由于Dio会自动将非2xx的回复视为错误，因此这个bool几乎不会用到
  bool get isSuccess => statusCode.toString().startsWith("2");
}

extension DioExceptionExtension on DioException {
  /// 如果它的error是Bug格式，那么就算是包裹了Bug类型
  bool get isWrapBug => error is Bug;

  /// 如果dio请求是在interceptor throw的Bug
  /// 那么Bug本身会被Dio包装过，此时需要多解开一层包装
  String get reason {
    if (!isWrapBug) {
      throw BugDev("DioExcetion[${toString()}]并非通过throw Bug抛出");
    }
    return (error as Bug).reason;
  }
}
